function setMenuItemsHeight()
{
	document.getElementById('submenu_view_by_company').style.height = $('body').innerHeight()-82-40*4+'px';
	document.getElementById('submenu_accounts').style.height = $('body').innerHeight()-82-40*4+'px';
	document.getElementById('submenu_types').style.height = $('body').innerHeight()-82-40*4+'px';
	document.getElementById('submenu_settings').style.height = $('body').innerHeight()-82-40*4+'px';
}

$("#right_menu ul li").live("click", function(){
    $("#right_menu ul li").removeClass("active");
    $(this).addClass("active");
});

$(document).ready(function(){
	$('#search_text').keypress(function(e){
		if(e.which == 13){
			$("#search_results").slideDown();
			if (!($("#search_results_field").is(':visible')))
			{
				$("#search_results").height("100%");
				$("#search_results_field").slideDown();
			}
			doSearch(document.getElementById('search_text').value, document.getElementById('search_area').value, 'search_results_field');
	    }
	});
	$('#search_area').keypress(function(e){
		if(e.which == 13){
			$("#search_results").slideDown();
			if (!($("#search_results_field").is(':visible')))
			{
				$("#search_results").height("100%");
				$("#search_results_field").slideDown();
			}
			doSearch(document.getElementById('search_text').value, document.getElementById('search_area').value, 'search_results_field');
	    }
	});
	
	setMenuItemsHeight();
	$(window).resize(function() {
		setMenuItemsHeight();
	});


	$('#menu_view_by_company').click(function() 
        {
            if($('#submenu_view_by_company').is(':visible'))
                $('#submenu_view_by_company').slideUp('');
            else
            {
                $('#submenu_accounts').slideUp('');
                $('#submenu_types').slideUp('');
                $('#submenu_settings').slideUp('');
                $('#submenu_view_by_company').slideDown('');
                expandMenu({controller: "viewbycompany", level: EXPAND_VIEW_BY_COMPANY});
           };
        }
    );


    $('#menu_accounts').click(function()
        {
            if($('#submenu_accounts').is(':visible'))
                $('#submenu_accounts').slideUp('');
            else
            {
                $('#submenu_settings').slideUp('');
                $('#submenu_view_by_company').slideUp('');
                $('#submenu_types').slideUp('');
                $('#submenu_accounts').slideDown('');
                expandMenu({controller: "accounts", level: EXPAND_ACCOUNTS});
           };
        }
    );


	$('#menu_types').click(function()
        {
            if($('#submenu_types').is(':visible'))
                $('#submenu_types').slideUp('');
            else
            {
                $('#submenu_accounts').slideUp('');
                $('#submenu_settings').slideUp('');
                $('#submenu_view_by_company').slideUp('');
                $('#submenu_types').slideDown('');
                expandMenu({controller: "types", level: EXPAND_TYPES});
           };
        }
    );
	
	$('#menu_settings').click(function() 
        {
            if($('#submenu_settings').is(':visible'))
                $('#submenu_settings').slideUp('');
            else
            {
                $('#submenu_accounts').slideUp('');
                $('#submenu_view_by_company').slideUp('');
                $('#submenu_types').slideUp('');
                $('#submenu_settings').slideDown('');
                expandMenu({controller: "settings", level: EXPAND_SETTINGS});
           };
        }
    );
	
	$("#button_show_menu").click(function() 
	{
		if ($("#hide_part").is(':visible'))
		{
			$("#hide_part").slideUp();
			$("#search_field").slideDown('fast');
		}
		else
		{
			$("#search_field").slideUp('fast');
			$("#hide_part").slideDown();
		}
	});
	
	$(".search_button").click(function()
	{
		$("#search_results").slideDown();
		if (!($("#search_results_field").is(':visible')))
		{
			$("#search_results_field").slideDown();
			$("#search_results").height("100%");
		}
	});
	
	$("#search_show_btn").click(function() {
		if ($("#search_results_field").is(':visible'))
		{
			$("#search_results_field").slideUp();
			$("#search_results").height(30);
		}
		else
		{
			$("#search_results").height("100%");
			$("#search_results_field").slideDown();
		}
	});
});